//
//  CompanyTableViewController.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/3.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "CompanyTableViewController.h"
#import "CompanyTableViewCell.h"
#import "CommendTableViewController.h"
#import "InstallationPointsTableViewController.h"
#import "AppDelegate.h"
#import "AFNetworking.h"
#import "Constant.h"
#import "BlueSkyAngel.h"

@interface CompanyTableViewController ()

@property (nonatomic, strong)NSArray *array;
@property (weak, nonatomic) IBOutlet UILabel *nickname;
@property (weak, nonatomic) IBOutlet UILabel *iphone;
@property (weak, nonatomic) IBOutlet UILabel *address;

@end

@implementation CompanyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    AFHTTPRequestOperationManager *request = [AFHTTPRequestOperationManager manager];
    request.responseSerializer = [AFJSONResponseSerializer serializer];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    dic[@"token"] = tempAppDelegate.token;
    
    [request POST:[NSString stringWithFormat:@"%@%@",url2,@"GetHigherMsg"] parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        if ([[NSString stringWithFormat:@"%@",dic[@"Status"]] isEqualToString:@"0"]) {
            NSDictionary *dic1 = dic[@"Data"];
            BlueSkyAngel *blueSkyAngel = [[BlueSkyAngel alloc] initWithDic:dic1];
            self.nickname.text = [NSString stringWithFormat:@"%@",blueSkyAngel.NickName];
            self.iphone.text = [NSString stringWithFormat:@"%@",blueSkyAngel.PhoneNum];
            self.address.text = [NSString stringWithFormat:@"%@",blueSkyAngel.Address];
        }else
        {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:dic[@"Message"] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"系统网络申请错误!");
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

//懒加载
- (NSArray *)array
{
    if (!_array) {
        _array = [NSArray array];
    }
    return _array;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            CommendTableViewController *commend = [storyboard instantiateViewControllerWithIdentifier:@"CommendTableViewController"];
            [self presentViewController:commend animated:YES completion:nil];
        }else
        {
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            InstallationPointsTableViewController *installation = [storyboard instantiateViewControllerWithIdentifier:@"InstallationPointsTableViewController"];
            [self presentViewController:installation animated:YES completion:nil];
        }
    }
}

@end
